/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;


import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import model.RDBS;

/**
 *
 * @author Carlos Suárez
 */
@WebService(serviceName = "WSServer")
public class WSServer {
    
    String server = "localhost";
    String database = "SCPA";
    String user = "root";
    String pass = "";
    /**
     * Web service operation
     */
//    @WebMethod(operationName = "setConnexion")
//    public String setConnexion(@WebParam(name = "server") String server, @WebParam(name = "database") String database, @WebParam(name = "user") String user, @WebParam(name = "password") String password) {
//        //TODO write your implementation code here:
//       if(server.isEmpty() || database.isEmpty() || user.isEmpty() || server == null || database == null || user == null){
//            return null;
//        }
//        RDBS rdbs = new RDBS(server,database,user,password);
//        if(!rdbs.isSetConnexion()){
//            return null;
//        }
//        
//        this.server = server;
//        this.database = database;
//        this.user = user;
//        this.pass = password;
//        
//        return "true";
//    }

    /**
     * Obtener Materias
     * @param idDocente
     * @return Materias
     */
    @WebMethod (operationName = "inicioSesion")
    public String inicioSesion (@WebParam (name ="login")String login, @WebParam (name = "password") String password)
    {
        //if (login.equals("") && password.equals("")) return "NULL";
        RDBS rdbs = new RDBS(server,database,user,pass);
        String resultado =  rdbs.inicioSesion(login,password);
        
        return resultado;
    }
    @WebMethod(operationName = "getMaterias")
    public String getMaterias(@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id,@WebParam(name = "idDocente") String id_docente) {
        //TODO write your implementation code here:
        if(id_docente.isEmpty()){
            return null;
        }
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> materias =  rdbs.getMaterias(token, user_id, id_docente);
        return materias.toString();
    }

    /**
     * Obtine los estudiantes por materias
     * @param idMateria
     * @return estudiantes de una materia
     */
    @WebMethod(operationName = "getEstudiantesbyMateria")
    public String getEstudiantesbyMateria(@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam(name = "idMateria") String idMateria) {
        //TODO write your implementation code here:
        
         if(idMateria.isEmpty()){
            return null;
        }
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> estudiantes =  rdbs.getEstudiantesbyMateria(token, user_id, idMateria);
        
        return estudiantes.toString();
    }
    @WebMethod(operationName = "getEstudiantesByActividad")
    public String getEstudiantesByActividad(@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam(name = "idTarea") String idMateria) {
        //TODO write your implementation code here:
        
         if(idMateria.isEmpty()){
            return null;
        }
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> estudiantes =  rdbs.getEstudiantesByActividad(token, user_id, idMateria);
        
        return estudiantes.toString();
    }
    
    /**
     * Obtine los estudiantes por materias 
     * @param token
     * @param user_id
     * @param idMateria
     * @return estudiantes de una materia y su asistencia
     */
    @WebMethod(operationName = "getEstudiantesbyMateriaforAsistencia")
    public String getEstudiantesbyMateriaforAsistencia(@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam(name = "idMateria") String idMateria) {
        //TODO write your implementation code here:
        
         if(idMateria.isEmpty()){
            return null;
        }
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> estudiantes =  rdbs.getEstudiantesbyMateriaforAsistencia(token, user_id, idMateria);
        
        return estudiantes.toString();
    }
   
    //public void setAsistencia (@WebParam (name = "idMateria") String idMateria, @WebParam (name = "idEstudiantes") ArrayList<Integer> idEstudiantes, @WebParam (name = "fecha") java.util.Date fecha, @WebParam (name="hora") int hora,@WebParam (name="asistencia") boolean asistencia )
     @WebMethod (operationName = "setAsistencia")
    public String setAsistencia (@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam (name = "idMateria") String idMateria, @WebParam (name = "idEstudiantes") ArrayList<Integer> idEstudiantes, @WebParam (name = "asistencia") ArrayList<Integer> asistio )
    {
        //String idEstudiante, String idMateria, String fechaAsistencia, String hora, String asistencia
       
       RDBS rdbs = new RDBS(server,database,user,pass);
       String resultado = rdbs.setAsistencia(token, user_id, idMateria, idEstudiantes, asistio);
       return resultado;
    }
    
      @WebMethod (operationName = "setActualizarAsistencia")
    public String setActualizarAsistencia (@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam (name = "idMateria") String idMateria, @WebParam (name = "idEstudiantes") ArrayList<Integer> idEstudiantes, @WebParam (name = "asistencia") ArrayList<Integer> asistio )
    {
        //String idEstudiante, String idMateria, String fechaAsistencia, String hora, String asistencia
       
       RDBS rdbs = new RDBS(server,database,user,pass);
       String resultado = rdbs.setActualizarAsistencia(token, user_id, idMateria, idEstudiantes, asistio);
       return resultado;
    }
    
    @WebMethod(operationName = "getActividadesByMateria")
    public String getActividadesByMateria(@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id,@WebParam(name = "idDocente") String idDocente, @WebParam(name = "idMateria") String idMateria) {
        //TODO write your implementation code here:
        
         if(idMateria.isEmpty()){
            return null;
        }
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> estudiantes =  rdbs.getActividadesByMateria(token, user_id, idDocente,idMateria);
        
        return estudiantes.toString();
    }
    
    /**
     * Web service operation
     */
    
    
    /**
     * Web service operation
     * @param idMateria
     * @param idActividad
     * @return 
     */
    
    
    @WebMethod (operationName = "getAcudientes")
    public String getAcudientes (@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam (name = "idEstudiantes") ArrayList<Integer> idEstudiantes)
    {
        if (idEstudiantes.isEmpty()) return null;
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> acudientes =  rdbs.getAcudientes(token, user_id, idEstudiantes);
        return acudientes.toString();
    }
    @WebMethod (operationName = "getAcudientesDeEstIncumplidos")
    public String getAcudientesDeEstIncumplidos (@WebParam (name ="idMateria")int idMateria, @WebParam (name = "idEstudiantes") ArrayList<Integer> idEstudiantes)
    {
        if (idEstudiantes.isEmpty()) return null;
        RDBS rdbs = new RDBS(server,database,user,pass);
        ArrayList<String> acudientesIncumplidos =  rdbs.getAcudientesDeEstIncumplidos(idMateria,idEstudiantes);
        return acudientesIncumplidos.toString();
    }
    
    @WebMethod (operationName = "registroTienda")
    public String registroTienda (@WebParam(name = "token") String token,@WebParam(name = "userId") String user_id, @WebParam (name = "regId") String regId)
    {
        if (regId.isEmpty()) return null;
        RDBS rdbs = new RDBS(server,database,user,pass);
        String respuesta =  rdbs.registroTienda(token, user_id, regId);
        return respuesta;
    }
    
     
   
}
